package com.suguowen.sblog.service;

import com.suguowen.sblog.bean.vo.ArticlesVO;
import com.suguowen.sblog.mapper.ArticleMapper;
import com.suguowen.sblog.mapper.DIYMapper;
import com.suguowen.sblog.mapper.TagMapper;
import com.suguowen.sblog.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HomeService {

    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private TagMapper tagMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DIYMapper diyMapper;
    @Autowired
    private Environment environment;

    /**
     * 所有封装后的文章信息
     * Article：title，createTime，
     * ArticleDetail：content
     * User：name
     * Tag：name
     * 文章详情链接
     */
    public List<ArticlesVO> getArticlesMsg(){
        List<ArticlesVO> list = diyMapper.selectArticle();
        return list;
    }

    // 符合特定标签的用户信息
    public List<ArticlesVO> selectArticleByTag(Integer tag_id) {
        List<ArticlesVO> list = diyMapper.selectArticleByTag(tag_id);
        System.out.println(list);
        return list;
    }
    // 日期分类
    public List<String> dateClassify(){
        return articleMapper.selectCreateTime();
    }
    // 符合特定日期的用户信息
    public List<ArticlesVO> getArticleByDate(String token) {
        String[] date = token.split("-");
        Integer year = Integer.valueOf(date[0]);
        Integer month = Integer.valueOf(date[1]);
        return diyMapper.selectArticleByDate(year,month);
    }
}